#include "GlobalNamespaceBuilder.h"

#include "ScriptCompiler/AST/NamespaceNode.h"

#include "ScriptCompiler/ASTBuilder/NamespaceContentBuilder.h"
#include "ScriptCompiler/ScriptFileContext.h"

CGlobalNamespaceBuilder::CGlobalNamespaceBuilder(std::shared_ptr<CScriptFileContext> InContext)
{
    Context = InContext;
    Result = std::make_shared<CNamespaceNode>(InContext);
}

bool CGlobalNamespaceBuilder::ReadCurentToken()
{
    //build namespace content
    auto NewNamespaceContentBuilder = std::make_shared<CNamespaceContentBuilder>(Context,Result);
    if(!NewNamespaceContentBuilder->ReadCurentToken())
    {
        return false;
    }

    auto Token=Context->GetCurrentToken();
    if(Token->Type!=EScriptTokenType::EndOfFile)
    {
        Context->RaiseError(10145,Token, U"early end of global namespace");
        return false;
    }
    //skip EndOfFile
    return true;

}
